package com.example.sprintboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sprintboot.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
    @Select("SELECT * FROM category")
    List<Category> selectAll();
    
    @Select("SELECT * FROM category WHERE parent_id = #{parentId}")
    List<Category> selectByParentId(@Param("parentId") Integer parentId);
    
    @Select("SELECT COUNT(*) FROM product WHERE category_id = #{categoryId}")
    int countProductsByCategoryId(@Param("categoryId") Integer categoryId);
    
    @Select("SELECT * FROM category WHERE is_leaf = 0 OR parent_id = 0 ORDER BY level, category_id")
    List<Category> selectParentCategories();
} 